<?php
	
	class AddProductModel extends Model{
		var  $table_name = 'gaoji_product';
			function AddProductModel(){
				parent::Model();
				$this->load->database();
				
				}
				
			function insertProduct($data){
				$this->db->insert('gaoji_product',$data);
				}

		function getSort(){
				//$this->db->order_by("order", "asc");
				$query=$this->db->get('gaoji_productsort');
				 
				foreach ($query->result() as $row ){
				$data[]=$row;
						}
						return $data;
			
				}
		function getParentSort(){
				$this->db->order_by('order','asc');
				$this->db->where('pid',0);
				$query=$this->db->get('gaoji_productsort');
				return $query->result();
			}
		function getSomeSort(){
				
			}
			
		function getChildren ($array,$pid=0,$y,&$tdata=array()){
			//$this->db->order_by("order", "desc");
		foreach ($array as $value){
			//print_r($value);
			if($value->pid==$pid){
			$n = $y + 1;
			$value->deep = $y;
			$tdata[]=$value;
			$this->getChildren($array,$value->sortid,$n,$tdata);
			}
		}
		return $tdata;
	}
	
	
			function page($per_nums,$start_pos){
				//$this->db->select('title');
				$this->db->limit($per_nums,$start_pos);
				$query = $this->db->get('gaoji_product');
				$data = $query->result();
				//print_r($data);
				$datas[] = $this->db->count_all($this->table_name);
				$datas[] = $data;
				
				//print_r($datas);
			return   $datas;	
				}
		}
?>